package com.lili.str;

/**
 * @Auther: 李 力
 * @Date: 2024/8/22
 * @Description: 最长公共前缀
 * @version: 1.0
 */
public class LeetCode14 {

    public static String longestCommonPrefix(String[] strs) {
        char[] first = strs[0].toCharArray();
        for (int i = 0; i < first.length; i++) {
            char ch = first[i];
            for (int j = 1; j < strs.length; j++) {
                if (strs[j].length() == i) {
                    return new String(first, 0, i);
                }
                if (ch != strs[j].charAt(i)) {
                    return new String(first, 0, i);
                }
            }
        }
        return strs[0];
    }
}
